package com.cet.lxf.oop.test04;

import java.util.StringJoiner;

/**
 * @program: algorithm
 * @description: 使用StringJoiner构造一个Select语句
 * @author: 陈恩涛
 * @create: 2021-06-28 10:03
 **/
public class Main07 {
    public static void main(String[] args) {
        String[] fields = { "name", "position", "salary" };
        String table = "employee";
        String select = buildSelectSql(table, fields);
        System.out.println(select);
        System.out.println("SELECT name, position, salary FROM employee".equals(select) ? "测试成功" : "测试失败");
    }

    private static String buildSelectSql(String table, String[] fields) {

        StringJoiner fieldsStringSj = new StringJoiner(", ","SELECT "," FROM "+ table);
        for (String field : fields) {
            fieldsStringSj.add(field);
        }
        return fieldsStringSj.toString();
    }
}
